package com.bw.day2task.mvp.view;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;

import com.bw.day2task.MainActivity;
import com.bw.day2task.R;
import com.bw.day2task.bean.BeanVideo;
import com.bw.day2task.mvp.content.LogContent;
import com.bw.day2task.mvp.model.LogModel;
import com.bw.day2task.mvp.presenter.LogPresenter;
import com.bw.library.mvp.view.BaseActivity;

public class RegAct extends BaseActivity<LogPresenter> implements LogContent.View {
    private ImageView img;
    private ImageView finsh;
    private EditText username;
    private EditText userpawd;
    private CheckBox cb;
    private Button okreg;
    private TextView sbmm;
    private TextView uprig;
    SharedPreferences.Editor edit;

    @Override
    public int bandLayout() {
        return R.layout.act_reg;
    }

    @Override
    public void initData() {
//        View decorView = getWindow().getDecorView();
//        decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
//        getWindow().setStatusBarColor(Color.TRANSPARENT);
        img.setImageResource(R.drawable.mn3);
        SharedPreferences user = getSharedPreferences("user", MODE_PRIVATE);
        edit = user.edit();
        String name = user.getString("name", "");
        String pass = user.getString("pass", "");
        boolean ucb = user.getBoolean("cb", false);
        cb.setChecked(ucb);
        mPresenter=new LogPresenter(this,new LogModel());
        username.setText(name);

        if (ucb){
            userpawd.setText(pass);
        }else {
            edit.clear();
            edit.commit();
        }
        okreg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String uname = username.getText().toString().trim();
                String upass = userpawd.getText().toString().trim();
                boolean checked = RegAct.this.cb.isChecked();
                edit.putBoolean("cb",checked);
                edit.commit();
                mPresenter.initreg();
//                if (uname.equals(name)&&upass.equals(pass)){
//
//
//
//                }else {
//                    ToastUtils.showShort("登录失败！");
//                }
            }
        });
        uprig.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(RegAct.this, LogAct.class);
                startActivity(intent);
            }
        });
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus && Build.VERSION.SDK_INT>=19){
            View decorView = getWindow().getDecorView();
            decorView.setSystemUiVisibility(
                              View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                             |View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                             |View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                             |View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                             |View.SYSTEM_UI_FLAG_FULLSCREEN
                             |View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY

            );
        }
    }

    @Override
    public void initView() {
        img = (ImageView) findViewById(R.id.img);
        finsh = (ImageView) findViewById(R.id.finsh);
        username = (EditText) findViewById(R.id.username);
        userpawd = (EditText) findViewById(R.id.userpawd);
        cb = (CheckBox) findViewById(R.id.cb);
        okreg = (Button) findViewById(R.id.okreg);
        sbmm = (TextView) findViewById(R.id.sbmm);
        uprig = (TextView) findViewById(R.id.uprig);
    }

    @Override
    public void ShowOk() {
        ToastUtils.showShort("登录成功！");
        Intent intent = new Intent(RegAct.this, MainAct.class);
        startActivity(intent);
    }

    @Override
    public String getname() {
        return username.getText().toString().trim();
    }

    @Override
    public String getpass() {
        return userpawd.getText().toString().trim();
    }

    @Override
    public void getvideo(BeanVideo beanVideo) {

    }
}
